package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TReasonDetail;
import com.ruoyi.system.service.ITReasonDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会计项目明细Controller
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/reasonDetail")
public class TReasonDetailController extends BaseController
{
    @Autowired
    private ITReasonDetailService tReasonDetailService;

    /**
     * 查询会计项目明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TReasonDetail tReasonDetail)
    {
        if(tReasonDetail.getTransactionDate1()!=null){
            tReasonDetail.setTD1(tReasonDetail.getTransactionDate1()[0]);
            tReasonDetail.setTD2(tReasonDetail.getTransactionDate1()[1]);
        }
        startPage();
        List<TReasonDetail> list = tReasonDetailService.selectTReasonDetailList(tReasonDetail);
        return getDataTable(list);
    }

    /**
     * 导出会计项目明细列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TReasonDetail tReasonDetail)
    {
        List<TReasonDetail> list = tReasonDetailService.selectTReasonDetailList(tReasonDetail);
        ExcelUtil<TReasonDetail> util = new ExcelUtil<TReasonDetail>(TReasonDetail.class);
        util.exportExcel(response, list, "会计项目明细数据");
    }

    /**
     * 获取会计项目明细详细信息
     */
    @GetMapping(value = "/{rid}")
    public AjaxResult getInfo(@PathVariable("rid") Long rid)
    {
        return AjaxResult.success(tReasonDetailService.selectTReasonDetailByRid(rid));
    }

    /**
     * 新增会计项目明细
     */
    @Log(title = "会计项目明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReasonDetail tReasonDetail)
    {
        return toAjax(tReasonDetailService.insertTReasonDetail(tReasonDetail));
    }

    /**
     * 修改会计项目明细
     */
    @Log(title = "会计项目明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReasonDetail tReasonDetail)
    {
        return toAjax(tReasonDetailService.updateTReasonDetail(tReasonDetail));
    }

    /**
     * 删除会计项目明细
     */
    @Log(title = "会计项目明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rids}")
    public AjaxResult remove(@PathVariable Long[] rids)
    {
        return toAjax(tReasonDetailService.deleteTReasonDetailByRids(rids));
    }
}
